import { useUserDetailStore } from "@/stores/userDetail";
import type { App } from "vue";
import type { DirectiveBinding } from "vue";


// 注册权限指令
export const regPermissions = (app: App<Element>) => {
  app.directive("permission", {
    mounted(el: HTMLElement, binding: DirectiveBinding<string>) {
      const userDetailStore = useUserDetailStore() // 获取用户详情仓库
      const permissions = userDetailStore.userDetail.permissions // 获取用户权限列表
      // 如果是超级管理员，则不需要做权限校验
      if (permissions.includes('*:*:*')) {
        return
      }
      // 如果不包含用户权限里不包含传过来的权限，则删除该元素
      if (!permissions.includes(binding.value)) {
        el.remove()
      }
    },
  })
}